---
title: "Acoustic Detections: Updates"
execute:
echo: false
include: false
output:
html_document:
df_print: paged
theme: readable
toc_float: true
toc: true
number_sections: false
toc_depth: 2
subtitle: analysis progress of the acoustic detections, master thesis Lotte Pohl, 16.2.2023
editor_options:
chunk_output_type: console
knitr:
opts_chunk:
collapse: true
format:
html:
page-layout: article
code-tools: true
fig-width: 8
fig-height: 5
---
::: column-body-outset
```{r libraries}
#| include: false
library (tidyverse)
library (lubridate)
library (leaflet)
library (tibble)
library (stringr)
library (ggsci)
library (pander)
library (mregions2)
library (fuzzyjoin)
library (sf)
# library(oce)
library (plotly)
library ("FactoMineR" )
library ("factoextra" )
```
```{r knityes_no}
knitting <- T
# if the document is not knitting right now, the prefix for path is set to ".", otherwise (for knitting) it's set to ".."
# pre <- ifelse(knitting %>% isFALSE(), ".", "..")
pre <- "C:/Users/lotte.pohl/Documents/github_repos/ADST_Mustelus_asterias"
```
```{r load_functions}
source (paste0 (pre, "/functions/functions_DST_presstemplogs.R" ))
source (paste0 (pre, "/functions.R" ))
```
```{r setup}
#| include: false
knitr:: opts_chunk$ set (warning = FALSE , message = FALSE )
```
```{r geo_info}
#| include: false
BPNS <- mregions2:: gaz_search (3293 ) %>% mregions2:: gaz_geometry ()
# sandbanks <- mregions2::gaz_search(c(2419, 4675, 2421, 2420)) %>% mregions2::gaz_geometry()
# for now, as long as mregions2 does not load in rstudio server
# bpns_boundaries <- st_read('./spatial_data/bpns_boundaries/bpns_boundaries.shp', layer = 'bpns_boundaries')
sandbanks <- st_read (paste0 (pre, '/spatial_data/sea_floor_geomorphology/sea_floor_geomorphology.shp' ), layer = 'sea_floor_geomorphology' )
OWFs <- st_read (paste0 (pre, "/spatial_data/OWFs_shapefiles/RD20140320_art8_1_20140328.shp" ))
```
```{r map_base}
#| include: false
map_base <- create_basic_map (include_regions = T) %>%
setView (3.5 , 51.5 , zoom = 10 ) %>% #setView(-3, 52.5, zoom = 9) %>%
addScaleBar (position = "topleft" , options = scaleBarOptions (maxWidth = 250 , imperial = F)) %>%
# add sandbanks
addPolygons (data= sandbanks,
fillColor = "#FFF2B3" ,
weight = 0 ,
fillOpacity = 0.5 ,
group = "Sandbanks" ) %>%
#label = ~preferredGazetteerName, labelOptions = labelOptions(noHide = F, textOnly = F, direction = "center", textsize = "12px", sticky = FALSE)
# add OWFs
addPolygons (data= OWFs,
color = "red" ,
opacity = 0.5 ,
fillColor = "red" ,
weight = 1 ,
fillOpacity = 0.2 ,
group = "OWFs" ) %>%
# add BPNS boundary
addPolygons (data = BPNS, color = "grey" ,
weight = 1 ,
opacity = 1.0 ,
fillOpacity = 0 ,
label = ~ preferredGazetteerName,
labelOptions = labelOptions (noHide = F, textOnly = F, direction = "center" , textsize = "12px" , sticky = FALSE ),
group = "Regions" ) %>%
leafem:: addMouseCoordinates ()
map_base
# base_map %>% save_leaflet(path = "./visualisation_ADST/maps_plots", filename = "basic_map_test", filetype = "pdf") #do with other map
```
```{r general_info}
#| include: false
project_code <- "ADST-Shark"
scientific_name <- "Mustelus asterias"
masterias_recaptured_serials <- c ("1293295" , "1293304" , "1293310" , "1293312" , "1293319" , "1293308" , "1293321" , "1293322" )
# bounding box
min_lon <- 0.8
max_lon <- 5
max_lat <- 53
min_lat <- 50
```
```{r load_RData}
masterias_info <- read_csv (paste0 (pre, "/RData/masterias_info.csv" ), show_col_types = FALSE )
masterias_info <- masterias_info %>% remove_double_cols ()
# masterias_ind_per_station <- read_csv(paste0(pre, "/RData/masterias_ind_per_station.csv"), show_col_types = FALSE)
masterias_detections <- read_csv (paste0 (pre, "/RData/masterias_detections.csv" ), show_col_types = FALSE )
# masterias_deployments <- read_csv(paste0(pre, "/RData/masterias_deployments.csv"), show_col_types = FALSE)
# detections_per_station <- read_csv(paste0(pre, "/RData/detections_per_station.csv"), show_col_types = FALSE)
# detections_per_deployment <- read_csv(paste0(pre, "/RData/detections_per_deployment.csv"), show_col_types = FALSE)
# close_stations <- read_csv(paste0(pre, "/RData/close_stations.csv"), show_col_types = FALSE)
deployments <- read_csv (paste0 (pre, "/RData/deployments.csv" ), show_col_types = FALSE )
```
```{r clean_animal_data}
masterias_info <- clean_animal_info (masterias_info, masterias_detections)
# make dateyear and time column in masterias_detections
masterias_detections <- masterias_detections %>% mutate (tag_serial_number = tag_serial_number %>% as.character (),
time = date_time %>% as.Date ("%H:%M" , tz = "UTC" ),
month = date_time %>% lubridate:: month (),
month_name = month.abb[month] %>% factor (levels = c ("Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" )),)
#
# masterias_detections$time <- masterias_detections$date_time %>% as.Date("%H:%M", tz = "UTC")
# # masterias_detections$season <- ifelse(month(masterias_detections$date_time) >=4 & month(masterias_detections$date_time) < 11, "summer", "winter") # only summer detections anyway
# # include months
# masterias_detections$month <- masterias_detections$date_time %>% lubridate::month()
# masterias_detections$month_name <-
#
# # input sex and release_date_time into detections dataframe
# masterias_detections$tag_serial_number <- masterias_detections$tag_serial_number %>% as.character()
masterias_detections <- masterias_detections %>% left_join (masterias_info %>% select (tag_serial_number, sex, release_dateyear), by = "tag_serial_number" )
# remove tags with only 1 detection
detection_summary <- masterias_detections %>% mutate (count = 1 ) %>% group_by (tag_serial_number) %>% summarise (n_detect = sum (count))
# input into masterias_info
masterias_info <- masterias_info %>% left_join (detection_summary, by = "tag_serial_number" )
tag_serial_number_omit <- detection_summary %>% filter (n_detect == 1 ) %>% select (tag_serial_number)
masterias_detections_clean <- masterias_detections %>% filter (! tag_serial_number %in% tag_serial_number_omit$ tag_serial_number)
# remove deployments outside of detection time frame
deployments <- deployments %>% filter (recover_date_time <= masterias_detections_clean$ date_time %>% max ()) %>% filter (deploy_date_time > masterias_detections_clean$ date_time %>% min ())
summary_masterias_length <- masterias_info %>% group_by (sex) %>% summarise (mean_length = length1 %>% mean (), sd_length = length1 %>% sd ())
rm (masterias_detections)
```
## some information
- Two tag serial numbers where only detected once: `r tag_serial_number_omit[1,1]` and `r tag_serial_number_omit[2,1]` , and where thus omitted.
- Females had a mean TL of `r summary_masterias_length %>% filter(sex == "f") %>% select(mean_length) %>% round(digits = 2) %>% pull()` cm ($\pm$ `r summary_masterias_length %>% filter(sex == "f") %>% select(sd_length) %>% round(digits = 2) %>% pull()` , n = `r masterias_info %>% filter(sex == "f") %>% nrow()` ), and males had a mean TL of `r summary_masterias_length %>% filter(sex == "m") %>% select(mean_length) %>% round(digits = 2) %>% pull()` cm ($\pm$ `r summary_masterias_length %>% filter(sex == "m") %>% select(sd_length) %>% round(digits = 2) %>% pull()` , n = `r masterias_info %>% filter(sex == "m") %>% nrow()` ).
<!-- # Detections per sex/season -->
- Last time, we wanted to resolve further how detections might differ between sex and season.
- I first divided the year into summer (from 1st of April to 30th of September) and winter (rest). During the winter period, however, there was not a single detection. So I then divided the detections by month.
- Detections range from April to October.
```{r near_stations}
open_stations <- deployments %>%
distinct (station_name, deploy_latitude, deploy_longitude)
# BPNS-cpower reefballs is not in the open deployments, beither is BPNSlottobuoy
close_stations <- open_stations %>%
filter (between (deploy_latitude, min_lat, max_lat)) %>%
filter (between (deploy_longitude, min_lon, max_lon))
rm (open_stations)
```
```{r map_releases_stations}
map_releases_stations <- map_base %>%
setView (3.5 , 51.5 , zoom = 10 ) %>%
# ADD RELEASED TAGS
addCircleMarkers (data= masterias_info,
lat = ~ release_latitude,
lng = ~ release_longitude,
weight= 0 ,# increase if black circle wanted
color = "black" ,
fillOpacity = 0.5 ,
radius = 6 ,
fillColor = "grey" ,
popup = ~ paste0 ("tag " , str_trunc (tag_serial_number, 3 , "left" , ellipsis = "" ), " (release: " , release_dateyear, "), " , sex),
group = "<span style=color:grey>released tags</span>" ) %>%
addCircleMarkers (data = close_stations,
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
fillColor = "black" ,
weight = 0 ,
radius = 3 ,
fillOpacity = 0.8 ,
popup = ~ station_name,
group = "<span style=color:black>stations</span>" ) %>%
addLayersControl (position = "topright" ,
overlayGroups = c ("<span style=color:grey>released tags</span>" , "<span style=color:black>deployments</span>" ),
options = layersControlOptions (collapsed = FALSE ))
# map_releases_stations
```
```{r areas}
# make overview of stations where M. asterias was detected and assign area to is (WS1, WS2, BPNS)
WS1_lon_threshold <- 3.38
WS2_lon_threshold <- 3.6
masterias_stations <- masterias_detections_clean %>% group_by (station_name) %>% summarise (deploy_latitude = mean (deploy_latitude), deploy_longitude = mean (deploy_longitude)) %>% mutate (area = ifelse (deploy_longitude < WS1_lon_threshold, "BPNS" , ifelse (deploy_longitude < WS2_lon_threshold, "WS1" , "WS2" )))
# include areas in masterias_detections as well
masterias_detections_clean <- masterias_detections_clean %>% left_join (masterias_stations %>% select (station_name, area), by = "station_name" )
# # areas work
# col_fun_rd <- ggsci::pal_ucscgb()(3)
# pal_rd <- leaflet::colorFactor(col_fun_rd, domain = masterias_stations$area)
#
# map_base %>% addCircleMarkers(data = masterias_stations,
# lat = ~deploy_latitude,
# lng = ~deploy_longitude,
# label = ~station_name,
# color = ~pal_rd(area))
rm (WS1_lon_threshold, WS2_lon_threshold)
```
```{r info_per_station_month_sex}
# maybe less resolution: spring (april - may), early summer (jun - jul), late summer (aug - sept), autumn (october)
detections_station_season_sex <-
masterias_detections_clean %>%
group_by (station_name, month, sex) %>%
count () %>%
rename (detections_count = n) %>%
arrange (desc (detections_count))
# detections_station_season_sex %>% View()
masterias_ind_per_station_season_sex <-
masterias_detections_clean %>%
distinct (station_name, tag_serial_number, month, sex)%>%
group_by (station_name, month, sex) %>%
count () %>%
rename (individuals_count = n) %>%
arrange (desc (individuals_count))
# masterias_ind_per_station_season_sex %>% View()
masterias_station_month_sex <- masterias_ind_per_station_season_sex %>% left_join (detections_station_season_sex, by = c ("station_name" , "sex" , "month" ), multiple = "all" ) %>% left_join (masterias_detections_clean %>% group_by (station_name) %>% select (station_name, deploy_latitude, deploy_longitude), by = "station_name" , multiple = "all" )
masterias_station_month_sex <- masterias_ind_per_station_season_sex %>% left_join (detections_station_season_sex, by = c ("station_name" , "sex" , "month" ), multiple = "all" ) %>% left_join (masterias_stations, by = "station_name" , multiple = "all" )
# masterias_station_month_sex %>% View()
masterias_station_month_sex <- masterias_station_month_sex %>% mutate (month_name = month.abb[month])
masterias_station_month_sex$ month_name <- masterias_station_month_sex$ month_name %>% factor (levels = c ("Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" ))
# summarise detections per sex
abs_detections <- masterias_station_month_sex %>% group_by (sex) %>% summarise (abs_detect = sum (detections_count))
abs_individuals <- masterias_detections_clean %>% group_by (sex) %>% summarise (abs_ind = tag_serial_number %>% unique () %>% length ())
abs_detect_ind <- abs_detections %>% left_join (abs_individuals, by = "sex" )
# rm(abs_detections, abs_individuals)
# find individuals per area per month
ind_area_month <- masterias_detections_clean %>% group_by (sex, area, month) %>% summarise (individuals_count = tag_serial_number %>% unique () %>% length ())
ind_area_month <- ind_area_month %>% mutate (month_name = month.abb[month])
ind_area_month$ month_name <- ind_area_month$ month_name %>% factor (levels = c ("Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" ))
rm (masterias_ind_per_station_season_sex, detections_station_season_sex)
```
- Overall, `r abs_detect_ind %>% filter(sex == "f") %>% select(abs_ind) %>% pull()` females were detected `r abs_detect_ind %>% filter(sex == "f") %>% select(abs_detect) %>% pull()` times and `r abs_detect_ind %>% filter(sex == "m") %>% select(abs_ind) %>% pull()` males were detected `r abs_detect_ind %>% filter(sex == "m") %>% select(abs_detect) %>% pull()` times.
- I divided the study area into 3 parts: WS1 (the first array in the Westerscheldt), WS2 (the second, more east array in the Westerscheldt) and BPNS.
## maps
::: panel-tabset
### detections per month
- The circle size corresponds to the number of detections from each station each month. It is relative to the total number of detections.
- The red circles are detections of females, the blue circles are detections of males.
```{r map_detections_station_month_sex}
#| include: true
# color palette
col_fun <- ggsci:: pal_locuszoom ()(masterias_station_month_sex$ month %>% unique () %>% length ())
pal <- leaflet:: colorFactor (col_fun, domain = masterias_station_month_sex$ month)
map_station_month_sex_detect <- map_releases_stations %>%
# APRIL
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 4 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#D43F3A" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#FF0000>April</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 4 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#D43F3A" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#FF0000>April</span>" ) %>%
# MAY
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 5 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#EEA236" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#EEA236>May</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 5 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#EEA236" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#EEA236>May</span>" ) %>%
# JUNE
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 6 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#5CB85C" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#5CB85C>June</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 6 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#5CB85C" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#5CB85C>June</span>" ) %>%
# JULY
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 7 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#46B8DA" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#46B8DA>July</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 7 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#46B8DA" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#46B8DA>July</span>" ) %>%
# AUGUST
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 8 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#357EBD" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#357EBD>August</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 8 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#357EBD" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#357EBD>August</span>" ) %>%
# SEPTEMBER
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 9 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#9632B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#9632B8>September</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 9 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#9632B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#9632B8>September</span>" ) %>%
# OCTOBER
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 10 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#B8B8B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#B8B8B8>October</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 10 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ log (((100 * detections_count) / masterias_detections_clean %>% nrow ()) + 1 ) * 15 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#B8B8B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#B8B8B8>October</span>" ) %>%
# SETTINGS
addLayersControl (position = "topright" ,
overlayGroups = c ("<span style=color:#FF0000>April</span>" ,
"<span style=color:#EEA236>May</span>" ,
"<span style=color:#5CB85C>June</span>" ,
"<span style=color:#46B8DA>July</span>" ,
"<span style=color:#357EBD>August</span>" ,
"<span style=color:#9632B8>September</span>" ,
"<span style=color:#B8B8B8>October</span>" ),
options = layersControlOptions (collapsed = FALSE )) %>%
hideGroup (c ("<span style=color:#EEA236>May</span>" ,
"<span style=color:#5CB85C>June</span>" ,
"<span style=color:#46B8DA>July</span>" ,
"<span style=color:#357EBD>August</span>" ,
"<span style=color:#9632B8>September</span>" ,
"<span style=color:#B8B8B8>October</span>" ))
map_station_month_sex_detect
```
### individuals per month
- The circle size corresponds to the number of individuals detected at a station each month. It is relative to the total number of detected individuals.
- The red circles are detections of females, the blue circles are detections of males.
```{r map_individuals_station_month_sex}
#| include: true
# color palette
col_fun <- ggsci:: pal_locuszoom ()(masterias_station_month_sex$ month %>% unique () %>% length ())
pal <- leaflet:: colorFactor (col_fun, domain = masterias_station_month_sex$ month)
map_station_month_sex_ind <- map_releases_stations %>%
# APRIL
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 4 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#D43F3A" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#FF0000>April</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 4 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#D43F3A" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#FF0000>April</span>" ) %>%
# MAY
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 5 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#EEA236" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#EEA236>May</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 5 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#EEA236" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#EEA236>May</span>" ) %>%
# JUNE
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 6 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#5CB85C" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#5CB85C>June</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 6 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#5CB85C" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#5CB85C>June</span>" ) %>%
# JULY
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 7 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#46B8DA" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#46B8DA>July</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 7 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#46B8DA" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#46B8DA>July</span>" ) %>%
# AUGUST
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 8 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#357EBD" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#357EBD>August</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 8 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#357EBD" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#357EBD>August</span>" ) %>%
# SEPTEMBER
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 9 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#9632B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#9632B8>September</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 9 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#9632B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#9632B8>September</span>" ) %>%
# OCTOBER
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 10 , sex == "f" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "red" ,
fillColor = "#B8B8B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#B8B8B8>October</span>" ) %>%
addCircleMarkers (data = masterias_station_month_sex %>% filter (month == 10 , sex == "m" ),
lat = ~ deploy_latitude,
lng = ~ deploy_longitude,
weight = 3 ,
radius = ~ ((100 * individuals_count) / masterias_detections_clean %>% select (tag_serial_number) %>% unique () %>% nrow ())/ 1.5 + 2 ,
fillOpacity = 0.7 ,
opacity = 1 ,
color = "blue" ,
fillColor = "#B8B8B8" ,
label = ~ paste0 ("month: " , month_name, ", station: " , station_name, ", (" , individuals_count, " individuals, " , detections_count, " detections), " , sex),
group = "<span style=color:#B8B8B8>October</span>" ) %>%
# SETTINGS
addLayersControl (position = "topright" ,
overlayGroups = c ("<span style=color:#FF0000>April</span>" ,
"<span style=color:#EEA236>May</span>" ,
"<span style=color:#5CB85C>June</span>" ,
"<span style=color:#46B8DA>July</span>" ,
"<span style=color:#357EBD>August</span>" ,
"<span style=color:#9632B8>September</span>" ,
"<span style=color:#B8B8B8>October</span>" ),
options = layersControlOptions (collapsed = FALSE )) %>%
hideGroup (c ("<span style=color:#EEA236>May</span>" ,
"<span style=color:#5CB85C>June</span>" ,
"<span style=color:#46B8DA>July</span>" ,
"<span style=color:#357EBD>August</span>" ,
"<span style=color:#9632B8>September</span>" ,
"<span style=color:#B8B8B8>October</span>" ))
map_station_month_sex_ind
```
:::
## barplots
::: panel-tabset
### detections per month
```{r plot_barplot}
#| include: true
ggplot (masterias_station_month_sex, aes (x = month, y = detections_count, fill = area)) +
geom_bar (position = "stack" , stat = "identity" ) +
facet_grid (sex ~ ., scales = "free_y" , space = "free_y" ) +
theme_minimal () +
ggsci:: scale_fill_jco () +
labs (x = "Month" , y = "Detections" , fill = "Area" )
```
*The upper facet corresponds to females (f), the lower facet corresponds to males (m)*.
### individuals per month
```{r plot_barplot2}
#| include: true
# need to find individuals per area per month
ggplot (ind_area_month, aes (x = month_name, y = individuals_count, fill = area)) +
geom_bar (position = "stack" , stat = "identity" ) +
facet_grid (sex ~ ., scales = "free_y" , space = "free_y" ) +
theme_minimal () +
# scale_y_discrete() +
scale_y_continuous (n.breaks= 2 ) +
ggsci:: scale_fill_jco () +
labs (x = "Month" , y = "Individuals" , fill = "Area" )
```
*The upper facet corresponds to females (f), the lower facet corresponds to males (m)*.
:::
## abacus plot
All detections, the colour denotes the area and the symbol denotes the sex.
```{r plot_abacus}
#| include: true
ggplot (masterias_detections_clean) +
geom_point (mapping = aes (x = date_time, y = tag_serial_number, color = area, pch = sex),
size = 5 ) +
ggsci:: scale_color_jco () +
labs (x = "Date" , y = "Tag serial number" , color = "Area" , pch = "Sex" ) +
theme_minimal ()
```
## interpretations
- We can see that females overall dominate the detections. By tagging 19 females and 11 males, we already integrated sex bias into the dataset. This bias further increased by only 4 males in contrast to 14 females being detected by a receiver.
- One male was detected in the WS1 area. It must have swum into the array, because the sharks tagged in the WS (5km north of Cadzand) were all female. Between May and August, males are only detected in the BPNS. In the 4 months that males were detected, it was a different male each time (tag 311 in April, 315 in May, 316 in July and tag 295 in August).
```{r investigation_males}
masterias_detections_clean %>% filter (sex == "m" ) %>% group_by (tag_serial_number, month, area) %>% summarise (individuals_count = tag_serial_number %>% unique () %>% length ())
```
- In September, 2 females (tag 299 and 307) are detected in the WS2 area. There are only a couple of detections (`r masterias_station_month_sex %>% ungroup() %>% filter(area == "WS2") %>% select(detections_count) %>% sum()` , on 22.09.2019 for tag 299 and 09.09.2019 for tag 307). Both these tags were also detected in the WS1 area in September 2019, tag 299 16 days before and 3 days after the detection in the WS2 area, and tag 307 1 day before and 7 days after. So tag 299 could have stayed in WS2 for 19 days, and tag 302 for 8 days.
```{r investigation_females_WS2_WS1}
masterias_detections_clean %>% filter (area == "WS2" ) %>% select (station_name, tag_serial_number, sex) %>% View ()
masterias_detections_clean %>% filter (area == "WS2" ) %>% select (tag_serial_number, date_time) %>% unique () %>% View ()
masterias_detections_clean %>% filter (area == "WS1" & month == "9" , detection_year == 19 , tag_serial_number %in% c ("1293299" , "1293307" )) %>% select (tag_serial_number, date_time) %>% unique () %>% View ()
```
## residency index (RI)
- The **overall Residency Index** (RI) is calculated by dividing the days of acoustic detections by the days of liberty (i.e. the days between the release and the last detection), for each tag.
- The **monthly Residency Index** is calculated by dividing the days of detections in a month by the days of that month, for each tag.
- I further subdivided the monthly RI by grouping the detections per tag and month into the three areas (WS1, WS2 and BPNS) to get a **Residency Index per area and month**.
```{r RI_calc}
# overall residency index, detected days / days of liberty
masterias_RI_all <- masterias_detections_clean %>% group_by (tag_serial_number, sex) %>% summarise (
release = release_dateyear %>% unique (),
min_detect = min (detection_dateyear),
max_detect = max (detection_dateyear),
days_at_liberty = (max_detect - release) %>% as.numeric (),
days_detected = detection_dateyear %>% unique () %>% length (),
RI_all = days_detected / days_at_liberty)
masterias_RI_all %>% View ()
# monthly RI per station
masterias_RI_month <- masterias_detections_clean %>% group_by (tag_serial_number, month_name, sex) %>%
summarise (days_detected = detection_dateyear %>% unique () %>% length (),
month_days = month %>% lubridate:: days_in_month () %>% as.numeric () %>% unique (),
RI_month = days_detected / month_days)
masterias_RI_month %>% View ()
masterias_RI_month_summary <- masterias_RI_month %>% group_by (month_name, sex) %>% summarise (mean_RI_month = mean (RI_month), sd_RI_month = sd (RI_month))
masterias_RI_area <- masterias_detections_clean %>% group_by (tag_serial_number, month_name, area, sex) %>%
summarise (days_detected = detection_dateyear %>% unique () %>% length (),
month_days = month %>% lubridate:: days_in_month () %>% as.numeric () %>% unique (),
RI_month = days_detected / month_days)
masterias_RI_area %>% View ()
```
```{r RI_plot_ideas}
# -------- month
# point plot
ggplot () +
geom_point (data = masterias_RI_month,
mapping = aes (x = month_name, y = RI_month, pch = sex, color = sex),
size = 4 ) +
geom_point (data = masterias_RI_month_summary,
mapping = aes (x = month_name, y = mean_RI_month, color = sex),
size = 5 ,
pch = 4 ) +
# scale_y_continuous(expand = c(0,0)) +
ggsci:: scale_color_nejm () +
labs (x = "Month" , y = "monthly Residency Index" ) +
theme_minimal ()
# line plot
ggplot (data = masterias_RI_month) +
geom_point (mapping = aes (x = month_name, y = RI_month),
size = 3.5 ) +
# scale_y_continuous(expand = c(0,0)) +
# ggsci::scale_color_jco() +
theme_minimal ()
# boxplot
ggplot (masterias_RI_month) +
geom_boxplot (aes (x = month_name, y = RI_month, fill = sex)) +
# facet_wrap(~sex) +
ggsci:: scale_fill_nejm () +
labs (x = "monthly Residency Index" ) +
theme_minimal ()
#--------------- area
# RI_area
ggplot (masterias_RI_area) +
geom_boxplot (aes (x = month_name, y = RI_month, fill = area)) +
facet_wrap (~ sex) +
ggsci:: scale_fill_jco () +
labs (y = "monthly Residency Index" , x = "Month" , fill = "Area" ) +
theme_minimal ()
```
::: panel-tabset
### overall RI
```{r plot_RI_overall}
#| include: true
ggplot () +
geom_col (data = masterias_RI_all, aes (y = RI_all, x = tag_serial_number, fill = sex)) +
# scale_color_continuous(c("red", "blue")) +
theme_minimal () +
ggsci:: scale_fill_nejm () +
theme (axis.text.x = element_text (angle = 60 , hjust = 1 )) +
labs (y = "overall Residency index" , x = "Tag Serial Number" , fill = "Sex" )
```
### monthly RI
```{r plot_RI_month}
#| include: true
ggplot (masterias_RI_month) +
geom_boxplot (aes (x = month_name, y = RI_month, fill = sex)) +
# facet_wrap(~sex) +
ggsci:: scale_fill_nejm () +
labs (y = "monthly Residency Index" , x = "Month" ) +
theme_minimal ()
```
### RI per area and month
```{r plot_RI_area}
#| include: true
ggplot (masterias_RI_area) +
geom_boxplot (aes (x = month_name, y = RI_month, fill = area)) +
facet_wrap (~ sex) +
ggsci:: scale_fill_jco () +
labs (y = "monthly Residency Index" , x = "Month" , fill = "Area" ) +
theme_minimal ()
```
*The left facet corresponds to females (f), the right facet corresponds to males (m)*.
:::
<!-- ### Correspondance Analysis (CA) of monthly RI values -->
<!-- ```{r CA_monthly_RI} -->
<!-- data(housetasks) -->
<!-- housetasks %>% head() -->
<!-- library("gplots") -->
<!-- # 1. convert the data as a table -->
<!-- dt <- as.table(as.matrix(housetasks)) -->
<!-- # 2. Graph -->
<!-- balloonplot(t(dt), main ="housetasks", xlab ="", ylab="", -->
<!-- label = FALSE, show.margins = FALSE) -->
<!-- chisq <- chisq.test(housetasks) -->
<!-- chisq -->
<!-- res.ca <- CA(housetasks, graph = FALSE) -->
<!-- print(res.ca) -->
<!-- ``` -->
## further analyses
- what kind of statistics could I do on these data? I would like to see if there are significant differences between sex, area and month (could also be grouped into season, i.e. early/mid/late summer).
- I am not sure how to proceed, because we have different n for males and females, and overall a very small number of individuals. Do you have a statistical method in mind that could come in handy in this case?
- In her master thesis, Jolien did a Correspondance Analysis (CA) on her monthly Residency Indices. What do you think of doing that here as well?
- I have wanted to analyse the dataset using the R packages *actel* <https://doi.org/10.1111/2041-210X.13503> and *RSP* <https://doi.org/10.1111/2041-210X.13484> for some weeks now. This would be my next step for the acoustic detection data.
:::